

import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import edu.towson.cosc603.coffeemaker.CoffeeMaker;
import edu.towson.cosc603.coffeemaker.Recipe;

public class CoffeeMakerTest extends TestCase {

	CoffeeMaker c;
	Recipe cookie;
	Recipe cookie1;
	Recipe cookie2;
	Recipe cookie3;
	@Before
	public void setUp() throws Exception {
		c = new CoffeeMaker();
		cookie = new Recipe();
		cookie1 = new Recipe();
		cookie2 = new Recipe();
		cookie3 = new Recipe();
		cookie.setAmtChocolate(2);
		cookie.setAmtCoffee(2);
		cookie.setAmtMilk(2);
		cookie.setAmtSugar(2);
		cookie.setName("cookie");
		cookie.setPrice(2);
		
		
		cookie1.setAmtChocolate(2);
		cookie1.setAmtCoffee(2);
		cookie1.setAmtMilk(2);
		cookie1.setAmtSugar(2);
		cookie1.setName("cookie1");
		cookie1.setPrice(2);
		
		
		cookie2.setAmtChocolate(2);
		cookie2.setAmtCoffee(2);
		cookie2.setAmtMilk(2);
		cookie2.setAmtSugar(2);
		cookie2.setName("cookie2");
		cookie2.setPrice(2);
		
		
		cookie3.setAmtChocolate(2);
		cookie3.setAmtCoffee(2);
		cookie3.setAmtMilk(2);
		cookie3.setAmtSugar(2);
		cookie3.setName("cookie3");
		cookie3.setPrice(2);
		
		
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testAddRecipe() {
		//base case.. successfully add a recipe
		assertTrue(c.addRecipe(cookie));
		//can not add the same item.
		assertFalse(c.addRecipe(cookie));
		
		//fill up the Coffee maker
		assertTrue(c.addRecipe(cookie1));
		assertTrue(c.addRecipe(cookie2));
		assertTrue(c.addRecipe(cookie3));
		//now the coffee maker is full.
		//we should not be able to add another reciepe
		Recipe r = new Recipe();
		assertFalse(c.addRecipe(r));
		
	}

	@Test
	public void testDeleteRecipe() {
		//can not delete a null item
		assertFalse(c.deleteRecipe(null));
		//can not delete a non existing item
		assertFalse(c.deleteRecipe(cookie));
		
		//can delete a existing item
		c.addRecipe(cookie);
		assertTrue(c.deleteRecipe(cookie));
		//re-check
		assertFalse(c.deleteRecipe(cookie));
	}

	@Test
	public void testEditRecipe() {
		//can not edit an existing item.
		assertFalse(c.editRecipe(cookie1, cookie));
		//successfuly edit
		c.addRecipe(cookie);
		assertTrue(c.editRecipe(cookie, cookie1));
		
	}

	@Test
	public void testAddInventory() {
		//fail cases
		assertFalse(c.addInventory(-1, 1, 1, 1));
		assertFalse(c.addInventory(1, -1, 1, 1));
		assertFalse(c.addInventory(1, 1, -1, 1));
		assertFalse(c.addInventory(1, 1, 1, -1));
		
		//valid cases
		assertTrue(c.addInventory(1, 1, 1, 1));		
	}


	@Test
	public void testMakeCoffee() {
		assertEquals(1,c.makeCoffee(cookie, 1));//not enough money, get the same money back
		assertEquals(1, c.makeCoffee(cookie, 3));//1 dollar refund.
		Recipe r = new Recipe();
		r.setAmtChocolate(16);
		assertEquals(1,c.makeCoffee(r, 1));//not enough inventory.
		
	}
	
	@Test
	public void testGetName(){
		c.addRecipe(cookie);
		assertEquals(cookie, c.getRecipeForName(cookie.getName())); //valid case
		
		//invalid case
		Recipe r = c.getRecipeForName("NONEXISTING_COOKIE");
		assertTrue(r.getName()==null);
		
	}

}
